$(function() 
{
	$( "a").each(function()
	{
		var rel    = $(this).attr ("rel");
		var titulo = $(this).attr ("title");
		
		if (rel.match ("modal"))
		{
			rel = rel.replace ("[", 	"");
			rel = rel.replace ("]", 	"");
			rel = rel.replace ("modal", "");
			
			var items = rel.split("x");
			var ancho = parseInt(items[0]);
			var alto  = parseInt(items[1]);
			
			if (ancho <= 0 || isNaN (ancho))
			{
				ancho = 640;
			}
			
			if (alto <= 0 || isNaN (alto))
			{
				alto = 480;
			}
			
			if (ancho > 0 && alto > 0)
			{
				$(this).click(function(e) 
				{
					e.preventDefault();
					
					var horizontalPadding = 10;
					var verticalPadding = 10;
					
					$.fx.speeds._default = 500;

					$('<iframe src="' + this.href + '" style="width: 99%;"/>').dialog({
	            		hide: 'highlight',
	            		autoOpen: true,
			            width: ancho,
			            center: true,
			            height: alto,
			            modal: true,
			            resizable: true,
	                    position: ['center', 40],
						autoResize: true,
						draggable: true,
			            overlay: {
			                opacity: 0.5,
			                background: "black"
			            },
						buttons: {
							'Cerrar': function() {
								$(this).dialog('close');
							}
						}

			        }).width(ancho - horizontalPadding).height(alto - verticalPadding);	        
				});
				

			}
		}			
	});
});